package com.hznu.jspFinal.controller;


import com.hznu.jspFinal.entity.AnswerRecord;
import com.hznu.jspFinal.entity.ExamRecord;
import com.hznu.jspFinal.myBeans.ExamAnswerDetail;
import com.hznu.jspFinal.myBeans.R;
import com.hznu.jspFinal.service.ExamRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "考试答案记录接口",value = "ExamRecord")
@RestController
@RequestMapping("/ExamRecord")
public class ExamRecordController {

    @Autowired
    ExamRecordService examRecordService;

    @ApiOperation(value = "修改考试答案")
    @PostMapping("/modify")
    public R modify(@RequestBody ExamAnswerDetail examAnswerDetail)
    {
        try
        {
            examRecordService.modify(examAnswerDetail);
            return R.ok() ;
        }catch(Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation(value = "通过学生id和考试id查找学生答题情况")
    @PostMapping("/findByStudent")
    public R findByStudent(@RequestBody AnswerRecord answerRecord)
    {
        try
        {
            return R.ok().put("data",examRecordService.findByStudent(answerRecord));
        }catch(Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation(value="返回单个题目已保存的答案")
    @PostMapping("/findByExercise")
    public R findByExercise(@RequestBody AnswerRecord answerRecord){
        try
        {
            return R.ok().put("data",examRecordService.findByExercise(answerRecord));
        }catch(Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

}
